//枚举转换
import {setVcode} from "./auth";
import store from '../store'

export function FormartPayType(payMethod) {
  switch (payMethod) {
    case 1:
      return '支付宝转账'
    case 2:
      return '支付宝吱口令'
    case 3:
      return '支付宝扫码'
    case 4:
      return '支付宝花呗'
    case 5:
      return '微信转账'
    case 6:
      return '微信扫码'
    case 7:
      return '银行卡'
    case 8:
      return '信用卡'
    case 9:
      return '支付宝转账自助'
    case 10:
      return '支付宝扫码自助'
    case 11:
      return '微信转账自助'
    case 12:
      return '微信扫码自助'
    case 13:
      return '银行卡自助'
  }
}

//订单状态转化
export function FormartOrderStatus(status) {
  switch (status) {
    case 1:
      return '未充值'
    case 2:
      return '提交第三方'
    case 3:
      return '充值成功'
    case 4:
      return '充值失败'
    case 5:
      return '已取消（手动取消）'
    case 6:
      return '超时过期'
    case 7:
      return '追分成功'
    case 8:
      return '待审核'
    case 9:
      return '审核失败'
  }

}


//收款方式转化
export function FormarOrderMethodType(payMethodType) {
  switch (payMethodType) {
    case 1:
      return '支付宝'
    case 2:
      return '微信'
    case 3:
      return '银行卡'
    case 4:
      return '花呗'
    case 5:
      return '信用卡支付宝'
    case 6:
      return '微信卡微信'
    case 7:
      return '支付宝自助'
    case 8:
      return '微信自助'
    case 9:
      return '银行卡自助'
  }
}

//评价等级转换
export function FormartCommentRank(rank) {
  switch (rank) {
    case 1:
      return '差评'
      break
    case 2:
      return '中评'
      break
    case 3:
      return '好评'
      break
  }
}

//评价星级转换
export function FormartCommentStar(star) {
  switch (star) {
    case 1:
      return '1星'
      break
    case 2:
      return '2星'
      break
    case 3:
      return '3星'
      break
    case 4:
      return '4星'
      break
    case 5:
      return '5星'
      break

  }

}

//安全码弹窗
export function useVcode(_this, call) {
  setTimeout(() => {
    _this.$prompt(`请输入安全码`, '安全码验证', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    }).then(({value}) => {
      setVcode(value)
      call()
    }).catch(() => {
      _this.$message({
        type: 'info',
        message: '已取消'
      })
    })
  }, 500)
}

//导出成Excel
export function downloadDataToFile(res, tHeader, filterVal, title) {
  require([], () => {
    const {export_json_to_excel} = require('../vendor/Export2Excel')
    const data = res.data.items.map(item => filterVal.map(i => {
      if (i.includes('.')) {
        let resultVal = item
        i.split('.').forEach(val => {
          resultVal = resultVal[val]
        })
        return resultVal
      } else if (i.includes(':')) {
        let type = i.split(":")[1]
        switch (type) {
          case "int":
            return parseInt(item[i.replace(':int', '')]) / 100
          default:
            if(store.getters[type])
              console.log(type)
              return store.getters[type][i.split(":")[0]]
        }
      } else {
        return item[i]
      }
    }))
    export_json_to_excel(tHeader, data, title)
  })
}




